<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>管理</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>
<script type="text/javascript">
	var $dg, $org_search;
	var currentYear = $.date.format(new Date(), "yyyy");
	var deptId = "${USER_SESSION.user.org_id}";
	$(function() {
		
		$dg = $("#dg").datagrid({
			url: $.webapp.root+"/admin/oa/forecast/getDeptOwnerList.do", 
			idField: 'id', fit: true, border: false, pageSize: 30, rownumbers: true, showFooter: true,
			remoteSort: true, toolbar: '#toolbars', striped:true, singleSelect: false,
			sortName: 'num', sortOrder: 'asc', queryParams: {"year": currentYear, "projDeptId": deptId},
			frozenColumns: [[
			    { field: 'ck', checkbox: true },
			    { field: 'id', title: 'id', hidden: true },
			    { field: 'custCategory', title: '顧客分類', width: 70 },

				{ field: 'custName', title: '顧客', width: 80 },
				{ field: 'caseName', title: '案件名称', width: 280 },
			]],
			columns: [[
				{ field: 'projOver', title: '项目完了', width: 70, align: 'center', rowspan:3 },
				{ field: 'projStatus', title: '项目状态', width: 70, align: 'center', rowspan:3 },
				{ field: 'projDegree', title: '项目进度', width: 70, align: 'center', rowspan:3, formatter:function(value, row, index){
					return undefined != value ? value+" %" : "" ;
				} },
				{ field: 'projDeptName', title: '部门名称', width: 80, align: 'center', rowspan:3 },
				{ field: 'projOwner', title: '项目拥有者', width: 80, align: 'center', rowspan:3 },
				{ field: 'pm', title: '项目经理', width: 80, align: 'center', rowspan:3, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{title:'一月份',colspan:4},
				{title:'二月份',colspan:4},
				{title:'三月份',colspan:4},
				{title:'四月份',colspan:4},
				{title:'五月份',colspan:4},
				{title:'六月份',colspan:4},
				{title:'七月份',colspan:4},
				{title:'八月份',colspan:4},
				{title:'九月份',colspan:4},
				{title:'十月份',colspan:4},
				{title:'十一月份',colspan:4},
				{title:'十二月份',colspan:4},
			],[ 
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
				{ title: 'ON', colspan:2 },
				{ title: 'OFF', colspan:2 },
            ],[ 
				{ field: 'zh_up_m1', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m1', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m1', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m1', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m2', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m2', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m2', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m2', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m3', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m3', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m3', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m3', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m4', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m4', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m4', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m4', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m5', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m5', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m5', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m5', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m6', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m6', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m6', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m6', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m7', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m7', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m7', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m7', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m8', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m8', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m8', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m8', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m9', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m9', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m9', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m9', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m10', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m10', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m10', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m10', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m11', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m11', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m11', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m11', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
				{ field: 'zh_up_m12', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'zh_down_m12', title: '下旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_up_m12', title: '上旬', width: 40, align: 'center', sortable: false },
				{ field: 'jp_down_m12', title: '下旬', width: 40, align: 'center', sortable: false, styler: function(value,row,index){
					return 'border-right: 1px solid red;';
				} },
				
            ]],
            enableHeaderClickMenu: true, enableHeaderContextMenu: false,
			onLoadSuccess: function(node, data) {
				$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
				$dg.datagrid('unselectAll');$dg.datagrid('clearSelections');$dg.datagrid('unselectAll');
				
				for(var i=1;i<=12;i++){
			        $($dg.datagrid('getColumnDom',"zh_up_m"+i)).css({"background": "#eee", "font-weight": "bold", "color": "#000"});
			        $($dg.datagrid('getColumnDom',"zh_down_m"+i)).css({"background": "#eee", "font-weight": "bold", "color": "#000"});
			        $($dg.datagrid('getColumnDom',"jp_up_m"+i)).css({"background": "#eee", "font-weight": "bold", "color": "#000"});
			        $($dg.datagrid('getColumnDom',"jp_down_m"+i)).css({"background": "#eee", "font-weight": "bold", "color": "#000"});
		        }
				for(var i=(new Date().getMonth()+1)+1;i<=12;i++){
			        $($dg.datagrid('getColumnDom',"zh_up_m"+i)).css("background","#f0fff0");
			        $($dg.datagrid('getColumnDom',"zh_down_m"+i)).css("background","#f0fff0");
			        $($dg.datagrid('getColumnDom',"jp_up_m"+i)).css("background","#f0fff0");
			        $($dg.datagrid('getColumnDom',"jp_down_m"+i)).css("background","#f0fff0");
		        }
				$($dg.datagrid('getColumnDom',"zh_up_m"+(new Date().getMonth()+1))).css("background","#55BF3B");
		        $($dg.datagrid('getColumnDom',"zh_down_m"+(new Date().getMonth()+1))).css("background","#55BF3B");
		        $($dg.datagrid('getColumnDom',"jp_up_m"+(new Date().getMonth()+1))).css("background","#55BF3B");
		        $($dg.datagrid('getColumnDom',"jp_down_m"+(new Date().getMonth()+1))).css("background","#55BF3B");
				
		        //页脚合并列（通过js来实现，easyui自身不支持）
		        var cur_td = $(".cols4").closest("div")
		        			.css({"text-align": "center", "width": "100%"})
		        			.closest("td").attr("colspan", "4")
		        			/*.css({"background": "#fff"})*/;
		        for(var i=0;i<3;i++){
		        	cur_td.next().remove();
		        }
			}
		}) ;
		
		/*
		*/
		$org_search = $("#org_search").combotree({
			url : $.webapp.root+"/static_res/org.tree.json",
			editable: false, lines:true, value: deptId,
			onChange: function(newValue, oldValue) {
				var y = $("#year_search").combobox("getValue"); 
				$dg.datagrid("load",{"year": y, "projDeptId": newValue});
			}
	    });
		
		$("#year_search").combobox({
			valueField: 'label', textField: 'value', value: currentYear,
			data: [
			       { label: '2013', value: '2013' },{ label: '2014', value: '2014' },{ label: '2015', value: '2015' },
			       { label: '2016', value: '2016' },{ label: '2017', value: '2017' },{ label: '2018', value: '2018' },
			       { label: '2019', value: '2019' },{ label: '2020', value: '2020' },{ label: '2021', value: '2021' },
			],
			panelHeight:'auto', editable:false, autoShowPanel: true,
			onSelect: function(record) {
				var did = $org_search.combotree("getValue") ;
				if(null != did && "" != did) {
					deptId = did ;
				}
				
				$dg.datagrid("load",{"year": record.value, "projDeptId": deptId});
			}
		}) ;
	});
	
	function form_edit(form) {
		var form_url = $.webapp.root+"/admin/oa/forecast/forecast_form_UI.do" ;
		if("E" == form) {
			var y = $("#year_search").combobox("getValue");
			var node = $dg.datagrid('getSelected');
			if (node) {
				form_url = $.webapp.root+"/admin/oa/forecast/forecast_form_UI.do?id="+node.id+"&year="+y ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true, maximizable: true,
			width: 800,
			height: 700,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg); } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function del() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return false;
		}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				$.post($.webapp.root+"/admin/oa/forecast/delete.do", {"ids" : ids.join(',')}, function(result) {
					if (result.status) {
						$dg.datagrid('unselectAll');$dg.datagrid('reload') ;
						alertify.success(result.msg);
						$.easyui.loaded();
					} else {
						alertify.warning(result.msg);
						$.easyui.loaded();
					}
				}, 'json').error(function() { $.easyui.loaded(); });
			}
		});
	}
	
	
</script>
</head>

<body>

	<div id="dg">
		<div id="toolbars">
			<form id="searchForm">
				<a onClick="form_edit('A');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">添加</a>
	            <a onClick="form_edit('E');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
	            <a onClick="del();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
	            <a onclick="$dg.datagrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
	            
	            <!-- 
	             -->
	           	 部门&nbsp;<input id="org_search" name="projDeptId" style="width:287px;height:25px;" />
	            
				<input id="year_search" style="width:100px;height:25px;" class="easyui-validatebox" type="text" />
				
           	</form>
        </div>
	</div>
</body>
</html>